// 拿不到，同样的代码其他网站可以拿到
const request = require('request');
const cheerio = require('cheerio');
const fs = require('fs');
request({
    url:'https://wp.sharkshopping.com/'
},(error,response,body)=>{
    let $ = cheerio.load(body);
    let arr = [];
    $('.advertisingbox').each((index,ele)=>{   
        let data ={};      
        data.url = $(ele).find('.advertisingimg img').attr('src');
        data.goodnum = $(ele).find('.goodNum').html();
        data.title = $(ele).find('.name').html();
        data.priceA = $(ele).find('.discountsRmb').html();
        data.priceB = $(ele).find('.preferential').html();
        arr.push(data);
    });
    // console.log(arr);
    let writestr = fs.createWriteStream('./homedata.json');
    let str = JSON.stringify(arr);
    writestr.write(str);
    writestr.end();
    writestr.on('finish',function(){
        console.log('写入完成');
        
    })
})